/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.yheriatovych.reductor.example;

import com.yheriatovych.reductor.Store;
import com.yheriatovych.reductor.example.model.AppState;
import com.yheriatovych.reductor.example.model.AppStateReducer;
import com.yheriatovych.reductor.example.reductor.filter.NotesFilterReducer;
import com.yheriatovych.reductor.example.reductor.notelist.NotesListReducer;
import com.yheriatovych.reductor.example.reductor.utils.SetStateReducer;
import com.yheriatovych.reductor.example.reductor.utils.UndoableReducer;
import com.yheriatovych.reductor.example.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.service.WindowManager;

/**
 * demo
 *
 * @since 2021-05-06
 */
public class MainAbility extends Ability {
    private Store<AppState> store;

    /**
     * 获取store对象
     *
     * @return store对象
     */
    public Store<AppState> getStore() {
        return store;
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        final AppStateReducer vanillaReducer = AppStateReducer.builder()
                .notesReducer(NotesListReducer.create())
                .filterReducer(NotesFilterReducer.create())
                .build();
        store = Store.create(
                new SetStateReducer<>(
                        new UndoableReducer<>(vanillaReducer)));
        getWindow().setInputPanelDisplayType(WindowManager.LayoutConfig.INPUT_ADJUST_PAN);
        super.setMainRoute(MainAbilitySlice.class.getName());
    }
}
